package com.example.accessibilityhelper.common.backtomain

import android.accessibilityservice.AccessibilityService
import android.view.accessibility.AccessibilityEvent
import com.example.accessibilityhelper.Step

abstract class RewindStep: Step() {

    abstract fun thisMatch(service: AccessibilityService,event: AccessibilityEvent):Boolean

    abstract fun executeOnce(service: AccessibilityService,event: AccessibilityEvent)

    override fun match(service: AccessibilityService, event: AccessibilityEvent): Boolean {
        return thisMatch(service,event)
    }

    override fun execute(service: AccessibilityService, event: AccessibilityEvent) {
        if (thisMatch(service,event)){
            executeOnce(service,event)
        }else{
            finish()
        }
    }
}